package com.tanhua.app.controller;

import com.tanhua.app.controllerservice.VideoService;
import com.tanhua.domain.vo.PageBeanVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.Map;

@RestController
public class VideoController {

    @Autowired
    private VideoService videoService;

    @GetMapping(name = "分页展示小视频内容",value = "/smallVideos")
    public ResponseEntity smallVideos(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer pagesize){

        if(page==0){
            page=1;
        }
        PageBeanVo pageBeanVo = videoService.smallVideos(page, pagesize);

        return ResponseEntity.ok(pageBeanVo);
    }

    @PostMapping(name = "小视频上传",value = "/smallVideos")
    public ResponseEntity toSmallVideos(MultipartFile videoThumbnail,MultipartFile videoFile) throws IOException {

        return videoService.toSmallVideos(videoThumbnail,videoFile);
    }



    @PostMapping(name = "小视频作者的关注",value = "/smallVideos/{uid}/userFocus")
    public ResponseEntity userFocus(@PathVariable("uid") Integer vid) throws IOException {

        return videoService.userFocus(vid);
    }


    @PostMapping(name = "小视频作者的关注撤销",value = "/smallVideos/{uid}/userUnFocus")
    public ResponseEntity userUnFocus(@PathVariable("uid") Integer vid) throws IOException {

        return videoService.userUnFocus(vid);
    }

    @PostMapping(value = "/smallVideos/{id}/like",name = "视频取消点赞")
    public ResponseEntity likeVideo(@PathVariable("id")String id){
        return videoService.likeVideo(id);
    }

    @PostMapping(value = "/smallVideos/{id}/dislike",name = "视频点赞")
    public ResponseEntity dislikeVideo(@PathVariable("id")String id){
        return videoService.dislikeVideo(id);
    }

    @GetMapping(value = "/smallVideos/{id}/comments",name = "评论列表")
    public ResponseEntity findComments(@PathVariable("id")String id,
                                       @RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer pagesize){
        return videoService.findComments(id,page,pagesize);
    }

    @PostMapping(value = "/smallVideos/{id}/comments",name = "发布小视频评论")
    public ResponseEntity saveComment(@PathVariable("id")String id, @RequestBody Map map){
        String comment =(String) map.get("comment");
        return videoService.saveComment(id,comment);
    }

    @PostMapping(value = "/smallVideos/comments/{id}/like",name = "视频评论点赞")
    public ResponseEntity likeCommentVideo(@PathVariable("id")String id){
        return videoService.likeCommentVideo(id);
    }

    @PostMapping(value = "/smallVideos/comments/{id}/dislike",name = "视频评论点赞取消")
    public ResponseEntity dislikeCommentVideo(@PathVariable("id")String id){
        return videoService.dislikeCommentVideo(id);
    }
}
